package com.raysun.androidbase.intent.extension

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.provider.ContactsContract
import androidx.activity.result.contract.ActivityResultContract

class PickSpecificContactContract : ActivityResultContract<Void?, Uri?>() {
    override fun createIntent(context: Context, input: Void?): Intent =
        Intent(Intent.ACTION_PICK).apply {
            type = ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE
        }

    override fun parseResult(resultCode: Int, intent: Intent?): Uri? {
        return resultCode.takeIf {
            it == Activity.RESULT_OK
        }?.let {
            intent?.data
        }
    }
}